<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link type="text/css" rel="stylesheet" href="/css/css_all.css" />
    <script src="https://code.jquery.com/jquery-1.11.0.js"></script>
    <script>
            function sendDate() {
                var params = {};
                //params.XX必须与Spring Mvc controller中的参数名称一致
                //否则在controller中使用@RequestParam绑定
                params.address = $('input[name="address"]').val();
                params.port = $('input[name="port"]').val();
                params.dbName = $('input[name="dbName"]').val();
                params.collection = $('input[name="collection"]').val();
                $.ajax({
                    async: true,
                    type: "POST",
                    url: "/DbToExcel/getInfo",//注意路径
                    data: params,
                    dataType:"json",
                    success: function (data) {
                       alert(data.msg)
                       saveExcel(data.entity.body)
                    },
                    error: function (data) {
                        alert(data);
                    }
                });
            }

           function saveExcel(data){
               var eleLink = document.createElement('a');
               eleLink.download = "filename.xls";
               eleLink.style.display = 'none';
               // 字符内容转变成blob地址
               var blob = new Blob([data]);
               eleLink.href = URL.createObjectURL(blob);
               // 自动触发点击
               document.body.appendChild(eleLink);
               eleLink.click();
               // 然后移除
               document.body.removeChild(eleLink);
           }
    </script>
</head>
<body>
<div class="screen_center">
<!--    <form action="/DbToExcel/getInfo">-->
        Address: <input name="address" value="192.168.1.173"> <br />
        Port: <input name="port" value="27017"> <br />
        DbName: <input name="dbName" value="天气"> <br />
        Collection: <input name="collection" value="机场id表"> <br />
        <button type="button" onclick="sendDate()">click me</button>
<!--        <input name="submit" type="submit" value="click me" onclick="sendDate()">-->
<!--    </form>-->
</div>

</body>
</html>